<?php
$path = $_SERVER['DOCUMENT_ROOT'];
require_once "$path/public/News.php";
include "$path/view/head.php";
$news = new News();
$categoryId = $_GET["id"];
$currentPage = empty($_GET["currentPage"]) ? 1 : $_GET["currentPage"];
$pageSize = empty($_GET["pageSize"]) ? 20 : $_GET["pageSize"];
$news->init($categoryId, $currentPage, $pageSize);
$dir_type = $_GET["type"];
$type = !empty($_GET["type"]) ? "type=" . $dir_type : "";
$pid = !empty($_GET["pid"]) ? "pid=" . $_GET["pid"] : "";
$id = !empty($_GET["id"]) ? "id=" . $_GET["id"] : "";
include "$path/view/banner.php";
include "$path/view/left.php";
?>
<div class="news_details">
    <div class="news_list">
        <ul>
            <?php

            foreach ($news->newsDatas["dataList"] as $key => $val) {
                ?>
                <li class="animate__animated animate__backInUp wow" data-wow-delay="0.<?php echo $key ?>s"
                    style="visibility: hidden; animation-delay: 0.<?php echo $key ?>s; animation-name: none;">
                    <a href="/<?php echo $basepath . "/" . ($cms->is_html ? "html/news/news_detail" . $val["idNews"] . ".html" : "view/news_detail.php?&detail_id=" . $val["idNews"] . "&$type&$pid&$id") ?>"
                       class="col-lg-12">
                        <div class="news_img col-lg-6">
                            <img src="/<?php echo $basepath ?>/assert/images/product.jpg"></div>
                        <div class="news_text col-lg-6">
                            <div class="news_tit"><?php echo $val["title"] ?></div>
                            <span>—— <?php echo $val["createdDate"] ?></span>
                            <p>
                                <?php echo substr($val["content"], 0, 500) . "..." ?>
                            </p>
                        </div>
                    </a>
                </li>
            <?php } ?>

        </ul>
    </div>
    <div class="page">
        <ul>
            <?php

            if ($news->currentPage > 1) {
                if ($cms->is_html) {
                    $p = $news->currentPage - 1;
                    echo "<li><a href=\"/$basepath/news$id" . ($p == 1 ? "" : "_$p") . ".html\">上一页</a></li>";
                } else {

                    echo "<li><a href=\"/$basepath/view/news.php?$type&$pid&$id&pageSize =20&currentPage =" . ($news->currentPage - 1) . "\">上一页</a></li>";
                }
            }
            $total = $news->totalPages;
            for ($index = 1; $index <= $total; $index++) {
                if ($news->currentPage == $index) {
                    echo "<li class='thisclass'><span>$index</span></li>";
                } else {
                    if ($cms->is_html) {
                        echo "<li><a href=\"/$basepath/news$id" . ($index == 1 ? "" : "_$index") . ".html\">$index</a></li>";
                    } else {
                        echo "<li><a href=\"/$basepath/view/news.php?$type&$pid&$id&pageSize=20&currentPage=$index\">$index</a></li>";
                    }
                }

            }
            if ($news->totalPages > 1 && $news->currentPage < $news->totalPages) {
                if ($cms->is_html) {
                    echo "<li><a href=\"/$basepath/news$id" . "_" . ($news->currentPage + 1) . ".html\">下一页</a></li>";
                } else {
                    echo "<li><a href=\"/$basepath/view/news.php?$type&$pid&$id&pageSize=20&currentPage=" . ($news->currentPage + 1) . "\">下一页</a></li>";
                }
            }
            if ($cms->is_html) {
                echo "<li><a href=\"/$basepath/news$id" . "_" . $news->totalPages . ".html\">尾页</a></li>";
            } else {
                echo " <li><a href=\"/$basepath/view/news.php?$type&$pid&$id&pageSize=20&currentPage=$news->totalPages\" class=\"c-nav ease moye\">尾页</a></li>";
            }
            ?>

        </ul>
    </div>

</div>

</div>

</div>

</div>
<?php include "$path/view/recommend.php"; ?>
<?php include "$path/view/footer.php"; ?>
